//File: timer.cpp
//Date: Fri Oct 15 2021
//Author: LiPeng(m201572398@alumni.hust.edu.cn)

#include "timer.hpp"
#include "debugutils.hpp"
#include <mutex>

// static members
std::map<std::string, std::pair<int ,double>> TotalTimer::rst;

void TotalTimer::print(){
    for(auto& itr : rst){
        print_debug("%s spent %lf secs in total, called %d times.\n", 
                    itr.first.c_str(), itr.second.second, itr.second.first);
    }
}

TotalTimer::~TotalTimer(){
    static std::mutex mt;
    std::lock_guard<std::mutex> lg(mt);
    auto& p = rst[msg];
    p.second += timer.duration();
    p.first ++;
}